<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"      
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets">
	
    <h:body>	
		<ui:composition template="/admin/template.xhtml">		    			
		<p:panel header="Administrace">	
			<h:panelGrid columns="2">
				<p:panel header="Správa administračních účtů" style="min-height: 1129px;">   
				   <h:form id="adminForm">	
					    	<p:dataTable id="seaspmTable" var="admin" value="#{adminBean.adminList}" rowKey="#{admin.id}" paginator="true" rows="15" paginatorAlwaysVisible="false" paginatorPosition="bottom" selection="#{adminBean.selectedAdmin}" selectionMode="single" emptyMessage="Žádní administrátoři nenalazeny"  tableStyle="min-width:300px;">
						        <f:facet name="header">
									<h:outputText value="Seznam administrátorů" />
						        </f:facet>
						        <p:column headerText="login">  
						            <h:outputText value="#{admin.username}" />  
						        </p:column>
						        <p:column headerText="Heslo">  
						            <h:outputText value="#{admin.password}" />  
						        </p:column>
						        <f:facet name="footer">  
					            	<p:commandButton  icon="ui-icon-pencil" value="upravit administrátora" update=":adminEditDialog" oncomplete="adminEditDialog.show()"/>
					                <p:commandButton  icon="ui-icon-document" value="nový administrátor"  update=":adminForm" oncomplete="adminNewDialog.show()"/>     
									<p:commandButton value="Odstranit"  actionListener="#{adminBean.deleteAdmin}" update=":adminForm,:growl"/>					       		
					       		</f:facet>   
					  	    </p:dataTable>
					</h:form>
					
					<p:dialog id="adminEditDialog" header="Editovat administrátora" widgetVar="adminEditDialog" resizable="false"  
					              width="300" showEffect="clip" hideEffect="fold" position="10,10">  
						      	<h:form>
						      	 	<h:panelGrid columns="2" cellpadding="4">
						      	 	   <h:outputText value="Login:" />    						      
							           <h:inputText value="#{adminBean.selectedAdmin.username}" style="width:150px" required="true"/>    
							           <h:outputText value="Heslo:" />    						      
							           <h:inputText value="#{adminBean.selectedAdmin.password}" style="width:150px" required="true"/>
						        	</h:panelGrid> 
						        	<p:commandButton value="Ulož změny"  actionListener="#{adminBean.updateAdmin}" update=":adminForm,:growl" oncomplete="adminEditDialog.hide()"/>  
						        </h:form>	
					 </p:dialog>
					
					<p:dialog id="adminNewDialog" header="Nový administrátor" widgetVar="adminNewDialog" resizable="false"  
					              width="300" showEffect="clip" hideEffect="fold" position="10,10">  
						      	 <h:form>   
						      	    <h:panelGrid columns="2" cellpadding="4">
						      	       <h:outputText value="Login:" />    						      
							           <h:inputText value="#{adminBean.newAdmin.username}" style="width:150px" required="true"/>    
							           <h:outputText value="Heslo:" />    						      
							           <h:inputText value="#{adminBean.newAdmin.password}" style="width:150px" required="true"/>
						        	</h:panelGrid> 
						        	<p:commandButton value="Vytvoř administrátora"  actionListener="#{adminBean.createAdmin}" update=":adminForm,:adminNewDialog,:growl" oncomplete="adminNewDialog.hide()" />
						        </h:form>	
					</p:dialog>
					
				</p:panel>
			</h:panelGrid>
		</p:panel>			
		</ui:composition>	
	</h:body>
</html>